<script language="JavaScript" type="text/JavaScript">
	var day1 = "";
	var time_b1 = "";
	var time_e1 = "";
	var day2 = "";
	var time_b2 = "";
	var time_e2 = "";
	var day3 = "";
	var time_b3 = "";
	var time_e3 = "";
	var day4 = "";
	var time_b4 = "";
	var time_e4 = "";
	var day5 = "";
	var time_b5 = "";
	var time_e5 = "";
	var day6 = "";
	var time_b6 = "";
	var time_e6 = "";
	var day7 = "";
	var time_b7 = "";
	var time_e7 = "";
	var alarm = "";
	
	function actionCmd(cmd){
		document.getElementById("view_header").style.visibility='visible';
		
		var html = '<fieldset><legend class="txt_module_head">เพิ่มข้อมูล</legend>'+
		'<table width="100%" border="0" cellspacing="3" cellpadding="2">'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash" ><span class="txt_module">รหัส ALarm</span> : </td>'+
		    '<td class="line_dash">'+				
		        '<input name="alarm_num" id="alarm_num" type="text" class="textBox_form" />  </td>'+
		  '</tr>'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">ALarm En</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<input name="alarm_en" id="alarm_en" type="text" class="textBox_form" />    </td>'+
		  '</tr>'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">ALarm Th</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<input name="alarm_th" id="alarm_th" type="text" class="textBox_form" />    </td>'+
		  '</tr>'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">Check duplicate</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<input name="chk_dup" id="chk_dup" type="radio" value="Y" /> Y <input name="chk_dup" id="chk_dup" type="radio" value="N" /> N </td>'+
		  '</tr>'+		  
		  '<tr>'+
		    '<td align="right" >&nbsp;&nbsp;    </td>';
		    if(cmd == "add"){
		    	html += '<td ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="cmdAlarm(\'0\',\'add\');" /></td>';
		    }else{
		    	html += '<td ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="cmdAlarm(\'0\',\'edit\');" /></td>';
		    }
		    
		  html += '</tr>'+
		'</table>'+
		'</fieldset>';
		alarm_add.innerHTML = html;
	}
	
	function actionEdit(alarm_num, alarm_en, alarm_th, chk_dup){
		actionCmd("edit");
		document.getElementById("alarm_num").disabled = true;
		document.getElementById("alarm_num").value = alarm_num;
		document.getElementById("alarm_en").value = alarm_en;									
		document.getElementById("alarm_th").value = alarm_th;
		var rchk_dup = document.getElementsByName("chk_dup");
		
		for(var i = 0; i < rchk_dup.length; i++){
			if(chk_dup == rchk_dup[i].value){				
				rchk_dup[i].checked = true;
				break;
			}
		}		
	}
	
	function cmdAlarm(alarm, cmd){
		//alert(cmd);
		var alarm_num = "";
		var alarm_en = "";
		var alarm_th = "";
		var chk_dup = "";
		
		if(cmd == "add"){
			alarm_num = document.getElementById("alarm_num").value;
			alarm_en = document.getElementById("alarm_en").value;			
			alarm_th = document.getElementById("alarm_th").value;			
			var rchk_dup = document.getElementsByName("chk_dup");
			//alert(rchk_dup.length);			
			for(var i = 0; i < rchk_dup.length; i++){
				if(rchk_dup[i].checked == true){
					chk_dup = rchk_dup[i].value;
				}
			}			
			//alert(chk_dup);
			
		}else if(cmd == "del"){
	    	var conf = confirm("ท่านต้องการจะ ลบ ข้อมูลใช่หรือไม่");
	    	if(conf == false){    
	    		return;
	    	}			
			alarm_num = alarm;
		}else if(cmd == "edit"){			
			prov_id = document.getElementById("prov_id").value;
			prov_desc = document.getElementById("prov_desc").value;			
		}
		
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmdalarm.php?session=" + session +'&alarm_num=' + alarm_num + "&alarm_en=" + alarm_en + "&alarm_th=" + alarm_th + "&chk_dup=" + chk_dup + "&action=" + cmd,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnProvince(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        		
	}
	
	function rtnProvince(txt){
		view.innerHTML = txt;
		waiting.innerHTML = "";
	}
	
	function cmdDayAlarm(alarm_num){
		alarm = alarm_num;
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmddayalarm.php?session=" + session +'&alarm_num=' + alarm_num + '&action=find',			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnDayALarm(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        		
		
		
	}
	
	function rtnDayALarm(txt){
		document.getElementById("view_header").style.visibility='visible';		
		var html = '<fieldset><legend class="txt_module_head">วันเวลาทำงานของ ALarm</legend>'+
		'<table width="100%" border="0" cellspacing="3" cellpadding="2">'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><span class="txt_module">วัน</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><span class="txt_module">เวลาเริ่มต้น</span></td>'+		        
		    '<td width="40%" align="center" class="line_dash"><span class="txt_module">เวลาเริ่มสิ้นสุด</span></td>'+		        
		    
		  '</tr>'+		
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day1" checked /><span class="txt_module">วันอาทิตย์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b1" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e1" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day2" checked /><span class="txt_module">วันจันทร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b2" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e2" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day3" checked /><span class="txt_module">วันอังคาร</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b3" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e3" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day4" checked /><span class="txt_module">วันพุทธ</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b4" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e4" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day5" checked /><span class="txt_module">วันพฤหัสบดี</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b5" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e5" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day6" checked /><span class="txt_module">วันศุกร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b6" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e6" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><input type="checkbox" name="day7" checked /><span class="txt_module">วันเสาร์</span></td>'+
		    '<td width="40%" align="center" class="line_dash"><input id="time_b7" type="text" class="textBox_time" value="0000" />  </td>'+		        
		    '<td width="40%" align="center" class="line_dash"><input id="time_e7" type="text" class="textBox_time" value="2359"/>  </td>'+		        
		  '</tr>'+		  
		  '<tr>'+
		    '<td width="20%" align="rigth" class="line_dash" ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="editDayAlarm();" /></td>'+
		    '<td width="40%" align="center" class="line_dash">&nbsp;</td>'+		        
		    '<td width="40%" align="center" class="line_dash">&nbsp;</td>'+		        
		  '</tr>'+		  		  
		'</table>'+
		'</fieldset>';
		alarm_add.innerHTML = html;
		//day1	
		//alert(txt);	
		var oRE = /<day1>(.*)<\/day1>/gi;				
		day1 = rxml(txt, oRE);			
		var cb_day1 = document.getElementsByName("day1");
		if(day1.length == 0 || day1 == "N"){
			cb_day1[0].checked = false;
		}else{
			cb_day1[0].checked = true;
		}
		oRE = /<time_b1>(.*)<\/time_b1>/gi;				
		time_b1 = rxml(txt, oRE);		
		document.getElementById("time_b1").value = time_b1;
		oRE = /<time_e1>(.*)<\/time_e1>/gi;				
		time_e1 = rxml(txt, oRE);
		document.getElementById("time_e1").value = time_e1;
		//day2		
		oRE = /<day2>(.*)<\/day2>/gi;				
		day2 = rxml(txt, oRE);	
		var cb_day2 = document.getElementsByName("day2");
		if(day2.length == 0 || day2 == "N"){
			cb_day2[0].checked = false;
		}else{
			cb_day2[0].checked = true;
		}		
		oRE = /<time_b2>(.*)<\/time_b2>/gi;				
		time_b2 = rxml(txt, oRE);		
		document.getElementById("time_b2").value = time_b2;
		oRE = /<time_e2>(.*)<\/time_e2>/gi;				
		time_e2 = rxml(txt, oRE);
		document.getElementById("time_e2").value = time_e2;
		//day3
		oRE = /<day3>(.*)<\/day3>/gi;				
		day3 = rxml(txt, oRE);				
		var cb_day3 = document.getElementsByName("day3");
		if(day3.length == 0 || day3 == "N"){
			cb_day3[0].checked = false;
		}else{
			cb_day3[0].checked = true;
		}				
		oRE = /<time_b3>(.*)<\/time_b3>/gi;				
		time_b3 = rxml(txt, oRE);		
		document.getElementById("time_b3").value = time_b3;
		oRE = /<time_e3>(.*)<\/time_e3>/gi;				
		time_e3 = rxml(txt, oRE);
		document.getElementById("time_e3").value = time_e3;
		//day4
		oRE = /<day4>(.*)<\/day4>/gi;				
		day4 = rxml(txt, oRE);				
		var cb_day4 = document.getElementsByName("day4");
		if(day4.length == 0 || day4 == "N"){
			cb_day4[0].checked = false;
		}else{
			cb_day4[0].checked = true;
		}						
		oRE = /<time_b4>(.*)<\/time_b4>/gi;				
		time_b4 = rxml(txt, oRE);		
		document.getElementById("time_b4").value = time_b4;
		oRE = /<time_e4>(.*)<\/time_e4>/gi;				
		time_e4 = rxml(txt, oRE);
		document.getElementById("time_e4").value = time_e4;
		//day5
		oRE = /<day5>(.*)<\/day5>/gi;				
		day5 = rxml(txt, oRE);				
		var cb_day5 = document.getElementsByName("day5");
		if(day5.length == 0 || day5 == "N"){
			cb_day5[0].checked = false;
		}else{
			cb_day5[0].checked = true;
		}								
		oRE = /<time_b5>(.*)<\/time_b5>/gi;				
		time_b5 = rxml(txt, oRE);		
		document.getElementById("time_b5").value = time_b5;
		oRE = /<time_e5>(.*)<\/time_e5>/gi;				
		time_e5 = rxml(txt, oRE);
		document.getElementById("time_e5").value = time_e5;
		//day6
		oRE = /<day6>(.*)<\/day6>/gi;				
		day6 = rxml(txt, oRE);				
		var cb_day6 = document.getElementsByName("day6");
		if(day6.length == 0 || day6 == "N"){
			cb_day6[0].checked = false;
		}else{
			cb_day6[0].checked = true;
		}										
		oRE = /<time_b6>(.*)<\/time_b6>/gi;				
		time_b6 = rxml(txt, oRE);		
		document.getElementById("time_b6").value = time_b6;
		oRE = /<time_e6>(.*)<\/time_e6>/gi;				
		time_e6 = rxml(txt, oRE);
		document.getElementById("time_e6").value = time_e6;
		//day7
		oRE = /<day7>(.*)<\/day7>/gi;				
		day7 = rxml(txt, oRE);				
		var cb_day7 = document.getElementsByName("day7");
		if(day7.length == 0 || day7 == "N"){
			cb_day7[0].checked = false;
		}else{
			cb_day7[0].checked = true;
		}												
		oRE = /<time_b7>(.*)<\/time_b7>/gi;				
		time_b7 = rxml(txt, oRE);		
		document.getElementById("time_b7").value = time_b7;
		oRE = /<time_e7>(.*)<\/time_e7>/gi;				
		time_e7 = rxml(txt, oRE);
		document.getElementById("time_e7").value = time_e7;
		waiting.innerHTML = '';        		
	}
	
	function getParam(){
		var d1 = "";		
		if(document.getElementsByName("day1")[0].checked == true)d1 = "Y";else d1="N";
		var d2 = "";		
		if(document.getElementsByName("day2")[0].checked == true)d2 = "Y";else d2="N";
		var d3 = "";		
		if(document.getElementsByName("day3")[0].checked == true)d3 = "Y";else d3="N";
		var d4 = "";		
		if(document.getElementsByName("day4")[0].checked == true)d4 = "Y";else d4="N";
		var d5 = "";		
		if(document.getElementsByName("day5")[0].checked == true)d5 = "Y";else d5="N";
		var d6 = "";		
		if(document.getElementsByName("day6")[0].checked == true)d6 = "Y";else d6="N";
		var d7 = "";		
		if(document.getElementsByName("day7")[0].checked == true)d7 = "Y";else d7="N";
			
		return "day1=" + d1 +
		"&time_b1=" + document.getElementById("time_b1").value + "&time_e1=" + document.getElementById("time_e1").value +
		"&day2=" + d2 +
		"&time_b2=" + document.getElementById("time_b2").value + "&time_e2=" + document.getElementById("time_e2").value +
		"&day3=" + d3 +
		"&time_b3=" + document.getElementById("time_b3").value + "&time_e3=" + document.getElementById("time_e3").value+
		"&day4=" + d4 +
		"&time_b4=" + document.getElementById("time_b4").value + "&time_e4=" + document.getElementById("time_e4").value+
		"&day5=" + d5 +
		"&time_b5=" + document.getElementById("time_b5").value + "&time_e5=" + document.getElementById("time_e5").value+
		"&day6=" + d6 +
		"&time_b6=" + document.getElementById("time_b6").value + "&time_e6=" + document.getElementById("time_e6").value+
		"&day7=" + d7 +
		"&time_b7=" + document.getElementById("time_b7").value + "&time_e7=" + document.getElementById("time_e7").value;
		
	}
	
	function editDayAlarm(){
		var param = getParam();
		alert(param);
		
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmddayalarm.php?session=" + session +'&alarm_num=' + alarm + "&" + param + "&action=edit" ,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnEditDayALarm(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        				
		
	}
	
	function rtnEditDayALarm(txt){
		waiting.innerHTML = '<span class="required">sucess...</span>';        				
	}
	
</script>
<div id="content">
	<div class="post">		
		<h2>แสดงข้อมูลเกี่ยวกับ ALarm</h2>
		<div class="entry">
			<div id="view">{VIEW_ALARM}</div>
		</div>
	</div>
	<div class="post"><div id="waiting"></div>					
		<div style="visibility:hidden" id="view_header"><h2>จัดการข้อมูลเกี่ยวกับ ALarm</h2></div>
		<div class="entry">							
			<div id="alarm_add"></div>
		</div>
	</div>
</div>